package com.jason.fontmetrics.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

/**
 * @DESC:
 * @Author: Jason
 * @Date: 16/8/28
 * @Time: 23:48
 */

public class FontView1 extends View {

    private static final String TEXT = "ap志哥ξτβбпшㄎㄊěǔぬも┰┠№＠↓";
    private static final String TAG = FontView1.class.getSimpleName();

    private Paint mPaint ; // 画笔
    private Paint.FontMetrics mFontMetrics; // 文本测量对象


    public FontView1(Context context) {
        this(context, null);
    }

    public FontView1(Context context, AttributeSet attrs) {
        super(context, attrs);

        initPaint();
    }

    private void initPaint() {
        // 实例化画笔
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setTextSize(70);
        mPaint.setColor(Color.BLACK);
        mPaint.setTypeface(Typeface.SERIF);

        // 文字的top跟随着 setTextSize 与 setTypeface 的设置变更大小

        mFontMetrics = mPaint.getFontMetrics();
        Log.d(TAG, "ascent----->>>>" + mFontMetrics.ascent);
        Log.d(TAG, "top----->>>>" + mFontMetrics.top);
        Log.d(TAG, "leading----->>>>" + mFontMetrics.leading);
        Log.d(TAG, "descent----->>>>" + mFontMetrics.descent);
        Log.d(TAG, "bottom------>>>>" + mFontMetrics.bottom);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawText(TEXT, 0,Math.abs(mFontMetrics.top), mPaint);
    }
}
